

if Tower == nil then
    Tower = {}
    Tower.__index = Tower
end

function Tower:new( o )
    o = o or {}
    setmetatable( o, Tower )
    return o
end


function Tower:Init()
    Tower.bossTower=nil
    Tower.towers={}

    Timers:CreateTimer(60*6,function ()
        Tower:ShowTowerWithWaring()
    end)
end


function Tower:ShowBossTower()
    Tower.bossTower=Tower:ShowTower(Tower.bossTower,Map.bossPos)
end

function Tower:HideBossTower()
    if Tower.bossTower==nil then
        return
    end
    Tower.bossTower:AddNewModifier(Tower.bossTower,nil,AbilitiesNames.modifier_dummy,{})
    Tower.bossTower:AddNoDraw()
end

function Tower:ShowTowerWithWaring()

    local targetPos,targetPosIndex=table.random(Map.centerPosList)
    Map.centerPosList[targetPosIndex]=nil
    for _,value in pairs(Hero.heroList)do
        if Player.playerList[value:GetPlayerID()].isAlive==true and value.mapPosIndex==targetPosIndex then
            MsgUtil:Top(value:GetPlayerID(),{text="#InfoTip_Tower_Spawn",style={color=ColorHex.Warn},duration=6})
            EmitSoundOnClient(SoundsNames.warning,PlayerResource:GetPlayer(value:GetPlayerID()))
        end
    end

    Timers:CreateTimer(10,function ()
        Tower:ShowTower(nil,targetPos)
    end)
end

function Tower:ShowTower(tower,pos)
    if tower==nil then
        tower= CreateUnitByName( "npc_dota_goodguys_tower1_top" , pos, true, nil, nil, DOTA_TEAM_NEUTRALS )
        tower:AddNewModifier(tower,nil,AbilitiesNames.modifier_dummy,{})
        tower:AddNewModifier(tower,nil,AbilitiesNames.modifier_tower,{})
        tower:AddNoDraw()
    end
    local dummy=Hero:FastDummy(pos,tower:GetTeamNumber(),7)
    local particle = ParticleManager:CreateParticle(ParticleNames.tower_spawn,PATTACH_ABSORIGIN_FOLLOW,dummy)
    ParticleManager:SetParticleControl(particle, 0,dummy:GetAbsOrigin())
    ParticleManager:ReleaseParticleIndex(particle)
    EmitSoundOn(SoundsNames.tower_spawn,dummy)
    Timers.CreateTimer(0.5,function ()
        tower:RemoveNoDraw()
        tower:RemoveModifierByName(AbilitiesNames.modifier_dummy)
        tower:SetAbsOrigin(pos)
    end)
    return tower
end
